package com.app.adnroid.sichuanxiaoke.cn.xiaokebusiness.Utils;

import android.util.Log;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Administrator on 2017/9/18.
 */

public class CardUtil {
    public static String getOrder(String price){

        //因为兴业银行的交易是以“分” 为单位，我们输入的是以“元为单位” 所以将元转换成分
        float i = Float.valueOf(price);
        final int newmoneyNumber= (int) (i*100);

        JSONObject data = new JSONObject();
        try {
            data.put("appid", "1100011000");
            data.put("phone", "40WX4I0M01");
            data.put("amount", newmoneyNumber);//价格
            data.put("mchnt_no", "309044353310001");
            data.put("trans_type", "01");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        OkGo.<String>post(Constant.CREATE_ORDER_URL)
                .upJson(data.toString())
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String s = response.toString();
                        String body = response.body();
                        try {
                            JSONObject object = new JSONObject(body);
                            String orderId = object.optString("order_id");
                            //toPayApp(orderId);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        Log.i("TAG", "Success---" + body);
                    }

                    @Override
                    public void onError(Response<String> response) {

                        Log.e("TAG", response.toString());

                        response.getException().printStackTrace();
                    }
                });

        return "";
    }
}
